<%@page contentType="text/html; charset=ISO-8859-1" %>
<%@page import="java.util.List, 
com.sebscape.sebcms.security.domain.Group, 
com.sebscape.sebcms.security.domain.User, 
com.sebscape.sebcms.security.domain.Role"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="/struts-tags" prefix="s" %>

	<%@page import="com.sebscape.sebcms.setup.domain.SetupConfiguration"%><style type="text/css">
		@import "http://ajax.googleapis.com/ajax/libs/dojo/1.3.2/dijit/themes/nihilo/nihilo.css";
		@import "http://ajax.googleapis.com/ajax/libs/dojo/1.3.2/dijit/themes/tundra/tundra.css";
	</style>    
	
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.3.2/dojo/dojo.xd.js"
		    djConfig="parseOnLoad:true, isDebug:false"></script>
	<script type="text/javascript">
		dojo.require("dojo.parser");
		dojo.require("dijit.layout.ContentPane");
		dojo.require("dijit.layout.TabContainer");
		dojo.require("dijit.form.Button");
	</script>

<c:url value="/admin/user/save" var="submitUrl"/>
<c:if test="${!empty sebcms_user.id}">
	<c:url value="/admin/user/update" var="submitUrl"/>
</c:if>

<c:if test="${!empty sebcms_error_map}">
	<ul>The following errors were found while registering:
	<c:forEach items="${sebcms_error_map}" var="error">
			<li><c:out value="${error.value}" /></li>
	</c:forEach>
	</ul>
</c:if>
<br/>

<form action="<c:out value="${submitUrl}" />" method="post">
<input type="hidden" name="user.id" value="<c:out value="${sebcms_user.id}" />" />
	<div id="mainTabContainer" dojoType="dijit.layout.TabContainer"
		style="float:left;width:624px;height:350px;padding:0;spacing:0" class="tundra">
		<div id="one" dojoType="dijit.layout.ContentPane" title="Login">
			<table width="100%">
				<tr>
					<td align="right">Username</td>
					<td><input type="text" name="user.username" value="<c:out value="${sebcms_user.username}" />"/></td>
				</tr>
				<tr>
					<td align="right">Password</td>
					<td><input type="password" name="user.password" /></td>
				</tr>
				<tr>
					<td align="right">Re-Type Password</td>
					<td><input type="password" name="confirm" /></td>
				</tr>
			</table>
		</div>
		<div id="two" dojoType="dijit.layout.ContentPane" title="Demographics">
			<table width="100%">
				<tr>
					<td align="right">Display Name</td>
					<td><input type="text" name="user.nickname" value="<c:out value="${sebcms_user.nickname}" />" /></td>
				</tr>
				<tr>
					<td>First Name</td>
					<td><input type="text" name="user.firstname" value="<c:out value="${sebcms_user.firstname}" />" /></td>
				</tr>
				<tr>
					<td align="right">lastname</td>
					<td><input type="text" name="user.lastname" value="<c:out value="${sebcms_user.lastname}" />" /></td>
				</tr>
			  	<tr>
					<td align="right">email</td>
					<td><input type="text" name="user.emailAddress" value="<c:out value="${sebcms_user.emailAddress}" />" /></td>
				</tr>
				<tr>
					<td align="right">Address</td>
					<td width="100%"><input type="text" name="user.demographic.address1" value="<c:out value="${sebcms_user.demographic.address1}" />"/></td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td><input type="text" name="user.demographic.address2"  value="<c:out value="${sebcms_user.demographic.address2}" />"/></td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td>City<input type="text" name="user.demographic.city"  value="<c:out value="${sebcms_user.demographic.city}" />" style="width:100px"/>
						ST <input type="text" name="user.demographic.state"  value="<c:out value="${sebcms_user.demographic.state}" />" style="width:2em"/>
						Zipcode <input type="text" maxlength="5" name="user.demographic.zip1" value="<c:out value="${sebcms_user.demographic.zip1}" />" style="width:3.5em"/>
						<input type="text"  style="width:3em" maxlength="4" value="<c:out value="${sebcms_user.demographic.zip2}" />" name="user.demographic.zip2" />
					</td>
				</tr>
			</table>
		</div>
		<div id="three" dojoType="dijit.layout.ContentPane" title="Groups">
			<table width="100%">		
			  	<tr>
					<td align="right">Current Group(s)</td>
					<td>
						<c:forEach items="${sebcms_user.groups}" var="group" varStatus="status" >
							<c:out value="${group.name}" /><br/>
						</c:forEach>
					</td>
				</tr>
			  	<tr>
					<td align="right">Group(s)</td>
					<td>
						<s:action namespace="/admin/group" name="list"/>
						<c:forEach items="${sebcms_list}" var="group" varStatus="status" >
							<c:set var="g" value="${group}" scope="request" />
							<%
								String isCheckedAtt = "";
								User user = (User)pageContext.findAttribute( "sebcms_user" );
								if( user != null ){ // null if adding new user.
									Group grp = (Group)pageContext.findAttribute( "g" );
									//out.println( "Comparing: " + grp );
									if( user.getGroups() != null && user.getGroups().contains( grp ) ){
										//out.println( "ITS A MATCH! " + grp );
										isCheckedAtt = "checked";
									}
								}
								request.setAttribute( "isCheckedAtt", isCheckedAtt );
							%>
							<input type="checkbox" name="groupIdList" value="<c:out value="${group.id}"/>" <c:out value="${isCheckedAtt}"/>/>&nbsp;<c:out value="${group.name}" /><br/> 
						</c:forEach>
					</td>
				</tr>
			</table>
		</div>
	</div>
<table style="clear:both">
	<tr>
		<td>&nbsp;</td>
		<td><input type="submit" value="save" name="submit" /></td>
	</tr>
</table>	
</form>